package com.zyx.concurrentdemo.mytest.c03;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Yaxi.Zhang
 * @since 2021/10/13 10:35
 */
@Slf4j(topic = "c.DeamonDemo")
public class DeamonDemo {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("结束任务");
        }, "t1");

        // 开启守护线程, 主线程结束后该线程结束
        t1.setDaemon(true);
        t1.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.debug("main线程结束");
    }
}
